Copyright(C) 1994,1995,1996,1997 Terumasa KODAKA , Takeshi KONO
■IDE interface
Basic knowledge
                o List of devices with built-in IDE interface
                  -----------------------------------------------+--------------------------------------------
                                                                 | Model
                  -----------------------------------------------+--------------------------------------------
                  2.5", 1.8" IDE built-in HD (not removable)     | PC-9801NS・UR・P・NL/R・NL/A, PC-9821Ld
                  2.5" IDE (pack for PC-9801NS/L)                | PC-9801NS/L
                  2.5" IDE (hard disk pack available for 98NOTE) | 98NOTE (excluding PC-9801N/NV/NL and the above 98NOTE)
                                                                 | PC-9801US, PC-H98T, PC-9821 first generation・Ce・Ts・Es
                  Up to 1 3.5" IDE                               | PC-9821Ap・As・Ae・Af・Ap2・As2・An・Cs2・Ce2・
                                                                 | Cf・Cx・Cb・Xt13・Cx2・Cb2, PC-9801BA・BX
                  Up to 2 3.5" IDE                               | PC-9821Ap3・As3・Bp・Bs・Be・Bf・
                                                                 | Xa・Xf・Xn・Xp・Xs・Xe・Xe10・
                                                                 | PC-9801BA2・BS2・BX2・BX3・BX4
                  Up to 4 3.5" IDE                               | PC-9821Xa16・Xa13・Xa12・Xa10・Xa9・Xa7・Xa7e
                                                                 | Xv13・Xb10
                  -----------------------------------------------+--------------------------------------------
                  * For PC-9821Cs2・Ce2・Cf・Cx・Cb・Cx2・Cb2, CD-ROM is connected as the second IDE.
                  * For machines equipped with file bays, a CD-ROM or HDD can be connected as a second IDE.
                o The BIOS interface of IDE hard disks is compatible with SASI hard disks. For this reason,
                  PC-9801-27 (SASI I/F board) cannot be used with a main unit equipped with an IDE hard disk.
                  However, if an IDE hard disk is not installed, the PC-9801-27 can be used even with models
                  that have a built-in IDE interface.
                o For models with a built-in IDE interface, when an IDE hard disk is installed, the IDE BIOS is
                  mapped to the expansion ROM area D8000 to D9FFFh, and the IDE BIOS work area is mapped to DA000
                  to DBFFFh. If an IDE hard disk is not installed, the IDE BIOS will not be mapped, so it can be
                  used as an expansion ROM area or UMB. However, on machines equipped with 98NOTE and PCI slots,
                  D8000 to DBFFFh cannot be used as an expansion ROM area or UMB even if an IDE hard disk is not
                  installed. In 98NOTE, the BIOS for system control is located in this area. This is because PCI BIOS
                  is installed on machines equipped with PCI slots.
                o The external interrupt of the IDE interface is fixed to INT3 (INT 11h). Also, the PC-9800's IDE
                  interface does not use DMA for data transfer with the IDE drive.
                u PC-9800 does not use the IDE's Master/Slave switching. Switching between the first and second drives
                  is done by switching all the I/O ports used by the drives using an external circuit.
                o The I/O addresses used by the IDE interface are as follows.
                  ------------+-------+-----+----------------------------+-------------------------------------
                  I/O address | Width | R/W | Content                    | I/O address in ISA
                  ------------+-------+-----+----------------------------+-------------------------------------
                  0430h       | BYTE  | R/W | IDE drive switching        | None
                  0432h       | BYTE  | R/W | IDE drive switching        | None
                  0435h       | BYTE  | R/W | Unknown                    | None
                  0640h       | WORD  | R/W | Data Register              | 01F0h
                  0642h       | BYTE  |  R  | Error Register             | 01F1h
                  0642h       | BYTE  |  W  | Write Precomp Register     | 01F1h
                  0644h       | BYTE  | R/W | Sector Count               | 01F2h
                  0646h       | BYTE  | R/W | Sector Number              | 01F3h
                  0648h       | BYTE  | R/W | Cylinder Low               | 01F4h
                  064Ah       | BYTE  | R/W | Cylinder High              | 01F5h
                  064Ch       | BYTE  | R/W | SDH Register               | 01F6h
                  064Eh       | BYTE  |  R  | Status Register            | 01F7h
                  064Eh       | BYTE  |  W  | Command Register           | 01F7h
                  074Ch       | BYTE  |  R  | Alternate Status Register  | 03F6h
                  074Ch       | BYTE  |  W  | Digital Output Register    | 03F6h
                  074Eh       | BYTE  |  R  | Digital Input Register     | 03F7h
                  ------------+-------+-----+----------------------------+-------------------------------------
                  * The "I/O address in ISA" column is the I/O address used by the IDE drive connected to the IBM PC/AT compatible machine.
Related           0000:0457h
                  0000:055Ch
                  0000:0598h
                  0000:059Ah
                  0000:05B0h
                  0000:05B1h
                  0000:05E8h
                  0000:05ECh
                  D800:0000~D800:1FFFh
                  DA00:0000~DA00:1FFFh
                  INT 11h (external interrupt)
                  INT 1Bh(IDE)
                  I/O 000Ah bit 1
I/O               0430h
Name              IDE bank switching
Undocumented
Target            (2 devices can be connected) IDE I/F equipped machine
Chip              IDE area
Function
                  [READ/WRITE]
                  bit 7~0: unknown
                            00h=IDE bank #1
                            01h=IDE bank #2
Explanation     o Details unknown
Related           I/O 0432h
I/O               0432h
Name              IDE bank switching
Undocumented
Target            (2 devices can be connected) IDE I/F equipped machine
Chip              IDE area
Function
                  [READ/WRITE]
                  bit 7~0: Bank selection
                            80h=Dummy write for status reading ([WRITE] only)
                            00h=IDE bank #1 selection
                            01h=IDE bank #2 selection
Explanation     o Select the IDE bank to be controlled by I/O 0640~064Eh, 074Ch, 074Eh.
                o On the PC-9800, bank selection is done by an external circuit connected to this port, which switches the entire drive's I/O ports.
Related           I/O 0430h
I/O               0435h
Name              Unknown
Undocumented
Target            PC-9821An・Ap3・As3・Cf・Cx・Cb・Xa10・Xa9・Xa7・Cx2・Cb2・Xt13・Xe10・Xa12・Xa7e, PC-9801BX4
Function
                  [READ/WRITE]
                  bit 7~2: unknown
                  bit 1: unknown
                         1=No IDE HDD
                         0=IDE HDD present
                  bit 0: unknown
Explanation     o Bit 1 is set depending on the presence or absence of an IDE HDD, but details are unknown.
Related           I/O 00F0h bit 5
I/O               0640h
Name              Data Register
Undocumented
Target            IDE I/F equipped machine
chip              IDE drive
Function
                  [READ/WRITE]
                  bit 15~0: data register
Explanation     o Perform data transfer. The data register width is 16 bits.
I/O               0642h
Name              Error Register,Write Precomp Register
Undocumented
Target            IDE I/F equipped machine
chip              IDE drive
Function
                  [READ] Error Register
                  bit 7: Bad Block Detected
                         1=Bad Block mark detected in ID field
                         0=normal
                  bit 6: Data ECC Error
                         1=An unrecoverable ECC error occurred in the data area
                         0=normal
                  bit 5: Media changed
                         1=media replaced
                         0=media not replaced
                         *Do not use PC-9800
                  bit 4: ID Not Found
                         1=ID not found
                         0=normal
                  bit 3: Media Change Requested
                         1=Media replacement required
                         0=Media replacement not requested
                         *Do not use PC-9800
                  bit 2: Aborted Command
                         1=Command execution was interrupted
                         0=normal
                  bit 1: Track0Error
                         1=Track0 could not be detected during Restore command execution
                         0=normal
                  bit 0: Address Mark Not Found
                         1=Address mark in data area could not be found
                         0=normal
Explanation     o Obtain the error status of the IDE drive
                  [WRITE] Write Precomp Register
                          44h=ECC length for Read/Write Long command 7 bytes
                          55h=Read Ahead Cache ON
                          AAh=Read Ahead Cache OFF
                          BBh=ECC length for Read/Write Long command 4 bytes
Explanation     o Configure various settings for the IDE drive.
I/O               0644h
Name              Sector Count
Undocumented
Target            IDE I/F equipped machine
chip              IDE drive
Function
                  [READ/WRITE]
                  bit 7~0: Sector Count
Description     o Set the number of sectors.
                o Specifying 00h behaves as if 256 were specified.
I/O               0646h
Name              Sector Number
Undocumented
Target            IDE I/F equipped machine
chip              IDE drive
Function
                  [READ/WRITE]
                  bit 7~0: Sector Number
Description     o Set the sector number.
I/O               0648h
Name              Cylinder Low
Undocumented
Target            IDE I/F equipped machine
chip              IDE drive
Function
                  [READ/WRITE]
                  bit 7〜0: Cylinder Low
Description     o Set the lower 8 bits of the cylinder number.
Related           I/O 064Ah
I/O               064Ah
Name              Cylinder High
Undocumented
Target            IDE I/F equipped machine
chip              IDE drive
Function
                  [READ/WRITE]
                  bit 7〜0: Cylinder High
Description     o Set the upper 8 bits of the cylinder number.
Related           I/O 0648h
I/O               064Ch
Name              SDH Register
Undocumented
Target            IDE I/F equipped machine
chip              IDE drive
Function
                  [READ/WRITE]
                  bit 7: Unused (set to 1)
                  bit 6: Binary Encoded Address Mode Select
                         1=Logical Block Address
                         0=Cylinder/Head/Sector
                         * Normally set to 0 on PC-9800
                  bit 5: Unused (set to 1)
                  bit 4: Drive Select
                  * Always set to 0 on PC-9800
                  bit 3~0: Head Select
Explanation     o Specify the head number
                u The PC-9800 does not use LBA addressing.
Related           I/O 074Eh
I/O               064Eh
Name              Status Register,Command Register
Undocumented
Target            IDE I/F equipped machine
chip              IDE drive
Function
                  [READ] Status Register
                  bit 7: Controller Busy
                         1=Controller is BUSY
                         0=normal
                  bit 6: Drive Ready
                         1=Drive is in READY state
                         0=normal
                  bit 5: Write Fault
                         1=A write error occurred.
                         0=normal
                  bit 4: Seek Complete
                         1=Seek operation completed successfully
                         0=Seek operation terminated abnormally
                  bit 3: Data Request
                         1=Drive is ready to transfer data
                         0=Drive is not ready to transfer data
                  bit 2: Corrected Data
                         1=A read error occurred but was corrected by ECC
                         0=normal
                  bit 1: Index
                         * Pulse output once per rotation of the disk
                  bit 0: Error
                         1=Some error occurred during command processing
                         0=normal
Explanation     o Obtain various statuses.
	          [WRITE] Command Register
                          00h= Get drive Feature byte
                          1xh= Recalibrate
                          20h= Read(with Retries)
                          21h= Read(without Retries)
                          22h= Read Long(with Retries)
                          23h= Read Long(without Retries)
                          30h= Write(with Retries)
                          31h= Write(without Retries)
                          32h= Write Long(with Retries)
                          33h= Write Long(without Retries)
                          3Ch= Write verify
                          40h= Read Verify(with Retries)
                          41h= Read Verify(without Retries)
                          50h= Format Track
                          7xh= Seek
                          8xh= Vendor Unique
                          90h= Execute Drive Diagnostic
                          91h= Initialize Drive Parameters
                          94h= Standby Immediate
                          95h= Idle Immediate
                          96h= Standby
                          97h= Idle
                          98h= Check Power Mode
                          99h= Set Sleep Mode
                          9Ah= Vendor Unique	
                          A0h= Send SCSI command to CD-ROM
                          C0h= Vendor Unique
                          C1h= Vendor Unique
                          C2h= Vendor Unique
                          C3h= Vendor Unique
                          C4h= Read Multiple
                          C5h= Write Multiple
                          C6h= Set Multiple Mode
                          C8h= Read DMA(with Retries)
                          C9h= Read DMA(without Retries)
                          CAh= Write DMA(with Retries)
                          CBh= Write DMA(without Retries)
                          DBh= Acknowledge media change
                          DCh= Boot - post-boot
                          DDh= Boot - pre-boot
                          DEh= Door lock
                          DFh= Door unlock
                          E0h= Standby Immediate
                          E1h= Idle Immediate
                          E2h= Standby
                          E3h= Idle
                          E4h= Read Sector Buffer
                          E5h= Check Power Mode
                          E6h= Set Sleep Mode
                          E8h= Write Buffer
                          E9h= Write same
                          ECh= Identify
                          EFh= Set Features
                          Fxh= Vendor Unique
Description     o Output commands to the IDE drive.
                o Some commands cannot be used depending on the drive. To find out which commands can be used, use the Identify command, etc.
Related           INT 1Bh - Function D0h(IDE)
                  INT 1Bh - Function E0h(IDE)
                  INT 1Bh - Function F0h(IDE)
I/O               074Ch
Name              Alternate Status Register,Digital Output Register
Undocumented
Target            IDE I/F equipped machine
chip              IDE drive
Function
                  [READ] Alternate Status Register
Explanation     o The contents are the same as the Status Register of I/O 064Eh. However, the status register can be read without clearing the interrupt output.
                  [WRITE] Digital Output Register
                  bit 7~4: Unused (set to 0000b)
                  bit 3: Unused (set to 1)
                  bit 2: Reset
                         1=Reset IDE drive
                         0=normal
                  bit 1: IRQ Enable
                         1=Disable interrupts from IDE drives
                         0=Allow interrupts from IDE drives
                  bit 0: Unused (set to 0)
Explanation     o Reset the IDE drive and set interrupts.
Related           I/O 064Eh
I/O               074Eh
Name              Digital Input Register
Undocumented
Target            IDE I/F equipped machine
chip              IDE drive
Function
                  [READ]
                  bit 7: unused
                  bit 6: Write Gate
                         1=normal
                         0=Drive is writing data onto media
                  bit 5~2: Head Select
                  * Inversion of Head Select of SDH register
                  bit 1,0: Drive Set1, Drive Set0
                           10b=Single mode/master selection
                           01b=Slave selection
Description     o Read various statuses of IDE drive.
Related           I/O 064Ch